package com.zhang.springcloud.app1.controller;

import brave.propagation.ExtraFieldPropagation;
import com.zhang.springcloud.api.dto.Users;
import com.zhang.springcloud.api.feignservice.IPersonService;
import com.zhang.springcloud.api.feignservice.IUsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhanghaolian
 * @date 2021/5/9 15:19
 */
@RestController
@Slf4j
public class App1Controller implements ApplicationContextAware {
    private ApplicationContext applicationContext;
    @Autowired
    private IUsersService usersService;

    /**
     * 这是一个测试方法<br>
     * @param agr 参数
     * @return 返回值是一个String
     */
    @GetMapping("/test")
    public String test(String agr) {
        log.info("I love idea.");
        return "hello: " + agr;
    }

    /**
     * 根据用户id查询用户
     * @param id
     * @return
     */
    @GetMapping("/controllerGetUsersById")
    public Users getUsersById(String id) {
        ExtraFieldPropagation.set("baggagefield", id);

        //System.out.println(applicationContext.getBean("com.zhang.springcloud.api.feignservice.IUsersService"));
        return usersService.getUserById(id);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
